package com.ruoyi.tester.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.tester.domain.TesterInterfaceCallLog;
import com.ruoyi.tester.mapper.TesterTaskCallLogMapper;
import com.ruoyi.tester.domain.TesterTaskCallLog;
import com.ruoyi.tester.service.ITesterTaskCallLogService;
import com.ruoyi.common.core.text.Convert;

/**
 * 任务调用日志Service业务层处理
 * 
 * @author SJ
 * @date 2022-04-26
 */
@Service
public class TesterTaskCallLogServiceImpl implements ITesterTaskCallLogService 
{
    @Autowired
    private TesterTaskCallLogMapper testerTaskCallLogMapper;

    /**
     * 查询任务调用日志
     * 
     * @param taskCallLogId 任务调用日志主键
     * @return 任务调用日志
     */
    @Override
    public TesterTaskCallLog selectTesterTaskCallLogByTaskCallLogId(Long taskCallLogId, String interfaceDesc, String status)
    {
        return testerTaskCallLogMapper.selectTesterTaskCallLogByTaskCallLogId(taskCallLogId, interfaceDesc, status);
    }

    /**
     * 查询任务调用日志列表
     * 
     * @param testerTaskCallLog 任务调用日志
     * @return 任务调用日志
     */
    @Override
    public List<TesterTaskCallLog> selectTesterTaskCallLogList(TesterTaskCallLog testerTaskCallLog)
    {
        return testerTaskCallLogMapper.selectTesterTaskCallLogList(testerTaskCallLog);
    }

    /**
     * 新增任务调用日志
     * 
     * @param testerTaskCallLog 任务调用日志
     * @return 结果
     */
    @Transactional
    @Override
    public int insertTesterTaskCallLog(TesterTaskCallLog testerTaskCallLog)
    {
        testerTaskCallLog.setCreateTime(DateUtils.getNowDate());
        int rows = testerTaskCallLogMapper.insertTesterTaskCallLog(testerTaskCallLog);
        insertTesterInterfaceCallLog(testerTaskCallLog);
        return rows;
    }

    /**
     * 修改任务调用日志
     * 
     * @param testerTaskCallLog 任务调用日志
     * @return 结果
     */
    @Transactional
    @Override
    public int updateTesterTaskCallLog(TesterTaskCallLog testerTaskCallLog)
    {
        testerTaskCallLog.setUpdateTime(DateUtils.getNowDate());
        testerTaskCallLogMapper.deleteTesterInterfaceCallLogByInterfaceCallLogId(testerTaskCallLog.getTaskCallLogId());
        insertTesterInterfaceCallLog(testerTaskCallLog);
        return testerTaskCallLogMapper.updateTesterTaskCallLog(testerTaskCallLog);
    }

    /**
     * 批量删除任务调用日志
     * 
     * @param taskCallLogIds 需要删除的任务调用日志主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteTesterTaskCallLogByTaskCallLogIds(String taskCallLogIds)
    {
        testerTaskCallLogMapper.deleteByTaskCallLogIds(Convert.toStrArray(taskCallLogIds));
        return testerTaskCallLogMapper.deleteTesterTaskCallLogByTaskCallLogIds(Convert.toStrArray(taskCallLogIds));
    }

    /**
     * 删除任务调用日志信息
     * 
     * @param taskCallLogId 任务调用日志主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteTesterTaskCallLogByTaskCallLogId(Long taskCallLogId)
    {
        testerTaskCallLogMapper.deleteTesterInterfaceCallLogByInterfaceCallLogId(taskCallLogId);
        return testerTaskCallLogMapper.deleteTesterTaskCallLogByTaskCallLogId(taskCallLogId);
    }

    /**
     * 新增接口调用日志信息
     * 
     * @param testerTaskCallLog 任务调用日志对象
     */
    public void insertTesterInterfaceCallLog(TesterTaskCallLog testerTaskCallLog)
    {
        List<TesterInterfaceCallLog> testerInterfaceCallLogList = testerTaskCallLog.getTesterInterfaceCallLogList();
        Long taskCallLogId = testerTaskCallLog.getTaskCallLogId();
        if (StringUtils.isNotNull(testerInterfaceCallLogList))
        {
            List<TesterInterfaceCallLog> list = new ArrayList<TesterInterfaceCallLog>();
            for (TesterInterfaceCallLog testerInterfaceCallLog : testerInterfaceCallLogList)
            {
                testerInterfaceCallLog.setInterfaceCallLogId(taskCallLogId);
                list.add(testerInterfaceCallLog);
            }
            if (list.size() > 0)
            {
                testerTaskCallLogMapper.batchTesterInterfaceCallLog(list);
            }
        }
    }
}
